package com.wzdigit.wms.wms.controller.dataPostback;


import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.wms.basic.domain.mid.IfPostback;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.Queryer;
import com.wzdigit.wms.basic.client.request.postback.PostbackRequest;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.mid.IfPostbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 拣货任务_PDA 前端控制器
 * </p>
 *
 * @author yangwenbiao
 * @since 2021-02-26
 */

@Slf4j
@RestController
@RequestMapping(value = WmsWareConstant.API_VERSION)
@Api(tags = "数据回传_PC")
public class dataPostbackController {

    public static final String REQUEST_MODEL = "/data_postback";

    @Autowired
    IfPostbackService ifPostbackService;

//    @ApiOperation(value = "查询")
//    @GetMapping(value = REQUEST_MODEL)
//    public PagerInfo<List<PicktaskMangementResp>> getTaskMmanagementInfo(Pager<?> page,
//                                                                         PicktaskMangementRequest picktaskMangementRequest,
//                                                                         HttpServletRequest servletRequest,
//                                                                         HttpServletResponse servletResponse) throws Exception {
//
//    }

    @ApiOperation(value = "查询")
    @GetMapping(value = REQUEST_MODEL + "/search")
    public PagerInfo<List<IfPostback>> search(Pager<?> page,
                                              PostbackRequest postbackRequest,
                                              HttpServletRequest servletRequest,
                                              HttpServletResponse servletResponse) throws Exception {
        try {
            Queryer<PostbackRequest> requestQueryer = new Queryer<>();
            requestQueryer.setPage(page);
            requestQueryer.setRequest(postbackRequest);

            PagerInfo<List<IfPostback>> pagerInfo = ifPostbackService.search(requestQueryer, servletRequest, servletResponse);
            return pagerInfo;
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "重新生成报文")
    @GetMapping(value = REQUEST_MODEL + "/re_biuld/{ifPostbackId}")
    public Result<IfPostback> reBiuld(@ApiParam("接口中间表-数据回传ID") @PathVariable(value = "ifPostbackId") Integer ifPostbackId,
                                      HttpServletRequest servletRequest,
                                      HttpServletResponse servletResponse) throws Exception {
        try {

            Result<IfPostback> result = ifPostbackService.reBiuld(ifPostbackId, servletRequest);
            return result;
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }

    @ApiOperation(value = "重新发送报文")
    @GetMapping(value = REQUEST_MODEL + "/re_rend/{ifPostbackId}")
    public Result<IfPostback> reSend(@ApiParam("接口中间表-数据回传ID") @PathVariable(value = "ifPostbackId") Integer ifPostbackId,
                                     HttpServletRequest servletRequest,
                                     HttpServletResponse servletResponse) throws Exception {
        try {
            Result<IfPostback> result = ifPostbackService.reSend(ifPostbackId, servletRequest);
            return result;
        } catch (RestStatusException ex) {
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw ex;
        }
    }


}
